<template>
	<view>
		<image src="../../static/logo-1.png" mode="widthFix" class="logo"></image>
		<view class="logo-title">EMOS企业在线办公系统</view>
		<view class="logo-subtitle">Ver 2050.2</view>
		<view class="register">
			<input placeholder="请输入手机号码" class="register-code" maxlength="11" type="number" v-model="registerCode" confirm-type="done"
			 @blur="overiphone(registerCode)" />
			<input placeholder="请输入密码" :password="true" class="register-code" maxlength="20" v-model="userpassword" confirm-type="done" />
		</view>
		<button class="login-btn" open-type="getUserInfo" @tap="login()">登陆系统</button>

		<button class="login-btns" plain type="default" @tap="wxlogin()">
			微信一键登录
			<icon class="icons" type="success_no_circle" size="30" />
		</button>
		<view class="register-container">

			没有账号？
			<text class="register" @tap="toRegister()">立即注册</text>
		</view>

	</view>
</template>
<script>
	export default {
		data() {
			return {
				registerCode: "", //帐号
				userpassword: "" //密码
			};
		},
		methods: {
			toRegister: function() {
				uni.navigateTo({
					url: '../register/register'
				});
			},
			wxlogin() { //微信一键登录
				wx.login({
					provider: "weixin",
					scopes:["auth_user"],
					success: (resp) => {
						let code = resp.code;
						console.log(code);
						uni.request({
							url:"http://localhost:8090/tb-user",
							method:"POST",
							data:{
								code:code
							}
						})
						 // 获取用户信息
						    // uni.getUserInfo({
						    //   provider: 'weixin',
						    //   success: function (resp) {
								  // console.log(resp);
						    //     let nickName = resp.userInfo.nickName;
						    //     let avatarUrl = resp.userInfo.avatarUrl;
						    //   }
						    // });
							
					}
				})

			},
			login() { //点击登陆进行直接登陆
				let iphone = this.overiphone(this.registerCode);
				if(iphone==false){
					return false;
				}
				console.log(this.registerCode);
				console.log(this.userpassword);

			},
			overiphone(registerCode) { //输入手机号码完成的时候
				if (registerCode === '') {
					callback1(new Error('手机号不可为空'));
					return false;
				} else {
					if (registerCode !== '') {
						var reg = /^1[3456789]\d{9}$/;
						if (!reg.test(registerCode)) {
							callback(new Error('请输入有效的手机号码'));
							return false;
						}
					}
					// callback();
				}

				function callback1(Error) {
					console.log("name", Error);
					uni.showModal({
						title: '手机号码不能为空',
					});

				}

				function callback(Error) {
					console.log("name", Error);
					uni.showModal({
						title: '请输入有效的手机号码',
					});
				}

			}

		}
	};
</script>
<style lang="less">
	@import url('login.less');
	
</style>
